<template>
	<view>
		<view class="address">
			<view class="address-body"  v-if="!address.cityName">
				<button type="primary" size="mini" @click="chooseAddress">请添加收货地址</button>
			</view>
			<view class="address-box" v-else  @click="chooseAddress">
				<uni-row>
					<uni-col :span="6" :offset="1">收货人： {{ address.userName }}</uni-col>
					<uni-col :span="9" :offset="8">电话： {{ address.telNumber }}<uni-icons type="right" size="14"></uni-icons></uni-col>
				</uni-row>
				<view class="user-address">
					<text class="name">收货人地址: </text>
					<text>{{ addressInfo }}</text>
				</view>
			</view>
			<image src="@/static/cart_border.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-address",
		data() {
			return {
			}
		},
		computed: {
			addressInfo() {
				if (!this.address.cityName) {
					return '暂无地址'
				} else {
					return `${this.address.provinceName} : ${this.address.cityName} : ${this.address.countyName} : ${this.address.detailInfo}`
				}
			},
			address() {
				return this.$store.state.user.address
			}
		},
		methods: {
			async chooseAddress() {
				let [err ,res] =	await uni.chooseAddress()
				if (err === null) {
					this.$store.commit('user/updataAddress', res)
				}
				console.log(err)
				
			}
			
		}
	}
</script>

<style scoped lang="scss">
.address {
	.address-body {
		height: 150rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.address-box {
		margin-top: 20rpx;
		font-size: 24rpx;
		.user-address {
			padding: 20rpx;
			display: flex;
			align-items: center;
			.name {
				width: 250rpx;
			}
		}
	}
	image {
		width: 100%;
		height: 10rpx;
	}
}

</style>
